#!/usr/bin/env python
import sys

import pika
import time

connection = pika.BlockingConnection(pika.ConnectionParameters(host='172.16.8.24', port=5672))
channel = connection.channel()

queue_name = "111111-1"
exchange_name = "111111-0"
channel.exchange_declare(exchange=exchange_name,
                         exchange_type='topic')
result = channel.queue_declare(exclusive=False, queue=queue_name)
print(queue_name)

binding_keys = "#"
for binding_key in binding_keys:
    channel.queue_bind(exchange=exchange_name,
                       queue=queue_name,
                       routing_key=binding_key)
print(' [*] Waiting for messages. To exit press CTRL+C')


def callback(ch, method, properties, body):
    print(" [x] Received %r" % body)
    time.sleep(body.count(b'.'))
    print(" [x] Done")
    ch.basic_ack(delivery_tag=method.delivery_tag)


channel.basic_qos(prefetch_count=1)
channel.basic_consume(callback,
                      queue=queue_name)

channel.start_consuming()
